Results 1 to 5 of 5

Thread: Creating Macro

  1. #1
    Join Date
    Aug 2003
    Posts
    160

    Unanswered: Creating Macro

    Hi! how can I create a query with onclick property of a comand button using VBA.

    Thanks
    Vad

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    The following will create a temporary query:

    dim dbs As Database, qdf As QueryDef
    Set dbs = CurrentDb()
    Set qdf = dbs.CreateQueryDef("", _
    "INSERT INTO FControl ( Code, [Value] ) " & _
    "SELECT 'NewestRelease' AS Code, '" & NewestRelease & "' AS [Value];")
    qdf.Execute


    If you do not want a temporary query, change it to :

    Set qdf = dbs.CreateQueryDef("QueryName", _
    "INSERT INTO FControl ( Code, [Value] ) " & _
    "SELECT 'NewestRelease' AS Code, '" & NewestRelease & "' AS [Value];")
    qdf.Execute
    Last edited by jmrSudbury; 11-04-03 at 14:51.

  3. #3
    Join Date
    Aug 2003
    Posts
    160

    How to create a query

    Hi! Actullay My problem was, I am creating a database in ms access 2000. I have created a technician form that consists of a list box(row source=Query) Option Group. This form consists of all the customers assigned to that technician.

    If I select One of the record below and click the find button, it is going to show the customer record that is assigned to that technician. How can I do that using code so that I need not to use a seperate query for each technician. I must able to get the form that I am using for each of the technicians, by jut entering the name of the new technician.

    I am sending you the screen shot of the form I designed.

    I think I provided all the information I needed. If not don't hesitate to ask me.
    Thanks
    Attached Thumbnails Attached Thumbnails screenhunter_005.bmp  
    Vad

  4. #4
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    On your main form, include the tech's name field. In your query,
    include the criteria where Tech = Forms!yourFormName!Tech.

    To get the current user from a window's session I use the following:

    Declare Function WNetGetUser Lib "mpr.dll" _
    Alias "WNetGetUserA" (ByVal lpName As String, _
    ByVal lpUserName As String, lpnLength As Long) As Long


    Public Function LoginName()
    Dim Status As Integer
    Dim lpName As String, lpUserName As String
    lpUserName = Space$(256)
    Status = WNetGetUser(lpName, lpUserName, 255)

    If Status = 0 Then
    LoginName = left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
    Else
    LoginName = ""
    End If
    End Function

  5. #5
    Join Date
    Aug 2003
    Posts
    160

    How to create a query

    Thank you very much. The thing is I am very much new to access. I don't know the windows session thing. I will try with the query idea u gave me.

    What I want was. If we add new technician name into the technician table, it must automatically come up with the query, and the Form I send you as attachment previously and also The form must display in menu items under technician forms. Is that possible to do.

    My boss is really pushing me on this. I am sending the database I created. If U can have a look at it.

    Any help
    Thanks
    Attached Files Attached Files
    Vad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •