Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    I don't know your data structure so I used a field name commonly found in tables as a unique identifier. Access Help has info on domain aggregate functions (DLookup, DSum, DAvg, etc).




    InputBox has only one button - OK.

    MsgBox can have various combinations of boxes.


    You will get more info from VBA Help on InputBox and MsgBox syntax.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    Ok -

    Now I am getting there. I have an "Add client" button with OnClick...

    DoCmd.GoToRecord , , acNewRec
    Me!ID.Locked = False
    If IsNull(DLookup("ID", "CLIENT", "ID='" & InputBox("Enter the ID to search") & "'")) Then
    MsgBox "There is no client associated with the ID you entered. You cannot enter OM_1 data for this client until there is a valid entry in the CLIENT table.", vbOKOnly
    Else
    MsgBox "A client with that ID exists. You may create a new record for this client.", vbOKOnly
    End If

    Which is perfect as far as it goes... However, I need another statement that runs something like (in English)

    If the ID is found, enter that ID into the frmOM_1 ID field and exit,
    Else if
    the ID is not found, go to the first record.

    Now for the latter half I can use:
    If IsNull([ID]) then
    DoCmd.GoToRecord , , acFirst

    ...because unless the ID field is filled during the procedure, it will (naturally) be empty. So, I just need a way to set the field if the ID is found (with the ID that has been found).

  3. #18
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    Closer...

    DoCmd.GoToRecord , , acNewRec
    Me!ID.Locked = False
    If IsNull(DLookup("ID", "CLIENT", "ID='" & InputBox("Enter the ID to search") & "'")) Then
    MsgBox "There is no client associated with the ID you entered. You cannot enter OM_1 data for this client until there is a valid entry in the CLIENT table.", vbOKOnly
    DoCmd.GoToRecord , , acFirst
    Else
    MsgBox "A client with that ID exists. You may create a new record for this client.", vbOKOnly

    (Now All I need here is a command to set the frmOM_1 ID = the tblCLIENT ID whenever it is found)

    End If

  4. #19
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Could use and populate a variable with the DLookup.

    Dim intID As Integer
    intID = Nz(DLookup(...),0)
    If intID = 0 Then
    'ID not found, do this with intID
    Else
    'ID found, do this with intID
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #20
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    Ummm ... thanks June7, but I am not quite sure I understand the application there...

    I need to capture the ID that is typed into the input box - and if the ID is found, then use that ID to set the ID field on the form to that ID value.

    I need to:

    Dim strID As String

    'Then I need to capture the Input box ID that was typed in

    strID = '....here I am stuck and need help...

    'then

    Me.ID = strID


    I may be being obtuse, but I am just not sure how the code you just posted helps me toward that end...

  6. #21
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Sorry, don't understand your confusion. Use the same DLookup expression already constructed. Populate a variable with result of DLookup. Use the variable for further processing.

    Do you understand use of variables in code?

    Is the ID a number or text field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #22
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    It's a text field ..and sorry but no, I don't understand the use of variables in code (as I say - I really am a COMPLETE novice to Access and VBa - a couple of weeks ago I opened Access for the first time in my life) So, I have ...

    Dim strID As String

    DoCmd.GoToRecord , , acNewRec
    Me!ID.Locked = False
    If IsNull(DLookup("ID", "CLIENT", "ID='" & InputBox("Enter the ID to search") & "'")) Then
    MsgBox "There is no client associated with the ID you entered. You cannot enter OM_1 data for this client until there is a valid entry in the CLIENT table.", vbOKOnly
    DoCmd.GoToRecord , , acFirst
    Me!ID.Locked = False
    Else
    MsgBox "A client with that ID exists. You may create a new record for this client.", vbOKOnly

    Me.ID = strID

    End If

    ...So how DO I populate the strID with the result of DLookup within the structure above?

  8. #23
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Dim strID As String

    DoCmd.GoToRecord , , acNewRec
    Me!ID.Locked = False

    strID = Nz(DLookup(...),"")

    If strID = "" Then
    ...
    Else
    ...
    End If


    http://office.microsoft.com/en-us/ac...001214213.aspx

    http://www.access-vba.net/introducti...ccess-vba.html

    http://www.lynda.com/Access-training...FQThQgod7lMAyg
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #24
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    YES! Thank you June7! The whole thing now works perfectly and precisely as I wanted. I now have precisely what I needed. You have (for what it is worth) earned my undying gratitude.

    Not sure how this forum works, but If I could tick a "solved" button - I would!
    Rramjet.

  10. #25
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Thread Tools dropdown above first post.

    Done.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 12-19-2012, 06:56 AM
  2. Replies: 5
    Last Post: 08-07-2012, 11:14 AM
  3. Replies: 2
    Last Post: 08-09-2010, 06:34 AM
  4. self-propagating input fields?
    By darklite in forum Forms
    Replies: 8
    Last Post: 02-23-2010, 03:39 PM
  5. Use Case Scenarios
    By scott.weppler in forum Access
    Replies: 0
    Last Post: 05-31-2009, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums