Results 1 to 2 of 2

Thread: Form Load Error

  1. #1
    Join Date
    Dec 2011

    Unanswered: Form Load Error

    On my previous form Capacity Sheet i send over a HG_ID value which does get displayed into the textbox HG_ID on my second form when it is loaded.

    Forms![Capacity Sheet].[HG ID] = Me.[HG ID]

    Private Sub Form_Load()
    Dim rst As Recordset
    If Not IsNull(HG_ID.Value) Then
    Set rst = CurrentDb.OpenRecordset("SELECT SUNDAY FROM Totals WHERE HG_ID = " & HG_ID.Value & ";")
    Text79.Value = rst.Fields(0)
    End If
    End Sub
    However after adding the code above on form load on my second form (B) this code does not give a value to the textbox Text79 since the value is null in HG_ID however if i put the same code above in a button i get a value. Im assuming its due to the fact that the textbox HG_ID on form (B) does not get its value right away, so how can i make sure that after the result is loaded i can do the rest of the code.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    you need to understand what the various events that Access provides as hooks to associate code

    there's load, open, got focus events and so on
    various things can or cant be done depending on what the event is.
    I suspect you'd be better off placing your code in another event. probably the forms got focus event

    if you only use the recordset to populate a control then you may be better of resource wise using a dlookup
    text79.value = dlookup("SUNDAY", "TOTALS", " HG_ID = " & HG_ID.Value")

    Also I'd stronlgy recommend that you give your controls meaning full names. the defautl from Access is fine as a default but text79 is not helping you when you or another person has to revisit this code in a few days / weeks / months / years
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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