Site Search:
Sign in | Join | Help

This Blog

Syndication

Tags

No tags have been created or used yet.

Archives

4Penny.net

Microsoft Access

Tricks and Tips for Microsoft Access
  • Insert statement in Access

    Set DB = DBEngine.OpenDatabase("C:\MyDir\MyDB.MDB")
    DB.Execute "INSERT INTO MyTable (MyField1, MyField2) VALUES ('abc',
    123)"
    DB.Close
    Set DB=Nothing
    End Sub

  • Get the current User

    Declare Function GetUserName Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
        As Long

     Function user()

        Dim s As String
        Dim cnt As Long
        Dim dl As Long
        Dim CurUser As String
        cnt = 199
        s = String(200, 0)
        dl = GetUserName(s, cnt)
        If dl <> 0 Then
            CurUser = Left$(s, cnt - 1)
        Else
            CurUser = ""
        End If
        user = CurUser
    End Function

     

  • Code to add items to a dropdown list in Access

    Private Sub cboSourceCodeTable_NotInList( _
                 NewData As String, Response As Integer)
      On Error Resume Next
      Response = acDataErrContinue
      If MsgBox("The source code '" & NewData _
              & "' is not in the list." _
              & vbLf & "Do you wish to add it?", _
              vbYesNo) = vbYes Then
        CurrentDb().Execute "insert into LeadSourceCode(Description) values ('" _
                          & NewData & "')"
        Response = acDataErrAdded
      End If
    End Sub