Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    24

    Unanswered: Access, VBA, form opened on new record, cant pre-populate field

    Private Sub City_NotInList(NewData As String, Response As Integer)
    DoCmd.OpenForm "City", , , , acFormAdd, acDialog, NewData
    Response = acDataErrAdded
    End Sub

    Private Sub Form_Open(Cancel As Integer)
    If Me.OpenArgs <> "" Then 'It has been opened for new records only
    CityName = Me.OpenArgs
    End If
    End Sub

    I've tried this on the forms current event with added condition of
    Me.NewRecord and with fully qualified name for CityName

    The form opens OK but the field is always blank - when the trace passes through the CityName assignment though, it makes the assignment successfully according to the value shown on hovering over the variable in theVBA editor

    Any comments much appreciated.

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Is the field CityName a bound field? If so, assigning a value to it before the form is open (or during the open event) should generate an error. If the field is not bound, it should work the way you want.

    I would suggest you assign the value to the field in the first set of code that is opening the second form, except you are opening the form with the acDialog flag, which is the similar to opening a Modal form (meaning the first set of code would be suspended until the second form closes).

    It works when using the On_Current event - will that suite your needs?

  3. #3
    Join Date
    Jan 2005
    Posts
    24
    Actually it doesnt work for me in the On_Current event, perhaps I was not specific enough. I tried On_Current after seeing the problem with On_Open and realising it was a sequencing issue.

    CityName is a bound field. I have tried without acDialog as well as with.Originally I tried to set the form as Modal but wondered if this was causing the problem so turned it off.

    I would suggest you assign the value to the field in the first set of code that is opening the second form, except you are opening the form with the acDialog flag, which is the similar to opening a Modal form (meaning the first set of code would be suspended until the second form closes).
    Not quite sure how to do the above - I assume you mean from the first procedure (frm1) after the DoCmd? As it stands the execution carries on to he end of the event block, but when I first started to code this I used
    Forms!Form2!CityName = Forms!Form1!City (the latter being the combo - both badly named) without success. - though I wonder now if I tried this under the On_Current Event (perhaps it was prior to the sequencing realisation)

    App is it work will try this out tomorrow!

Posting Permissions

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