Value of the Table

  • Thread starter Thread starter Deleted member 162737
  • Start date Start date
D

Deleted member 162737

Guest
Greetings my friends,

can someone help me with this matter?

I have one Table and there is only one row in it (and always will be only one row). This table has multiple columns and one of them is defined as AutoNumber and has random value.

Then I have one form with textbox where can user enter number.

I need help with code, I need to have something like this: if on click entered value from textbox is the same as value in first column (called ID) of the first row of Table (called temporarily), thenn et cetera...

I tried with command DLookup something like this:

Private Sub D001_Click()
If Me.UVKB.Value = DLookup("ID", "Registrovani", ???) Then
DoCmd.Close acForm, 500
DoCmd.OpenForm (0)
End If
End Sub

Maybe the problem is simple, I just started learning VBA?!
Thank you very much everyone in advance!
 
A DLookup() always returns the first value it finds in a table based on the criteria, so simply don't supply the criteria and you should get the result you are after.

DLookup("ID", "YourTempTable")
 
A DLookup() always returns the first value it finds in a table based on the criteria, so simply don't supply the criteria and you should get the result you are after.

DLookup("ID", "YourTempTable")
Thank You Minty for the support and help!

I applied but unfortunately it doesn't work (You can see code in attachment).
Did I miss something..?!
 

Attachments

  • Screenshot 2023-02-17 143120_CODE.png
    Screenshot 2023-02-17 143120_CODE.png
    7.9 KB · Views: 106
  • Screenshot 2023-02-17 143319_TABLE.png
    Screenshot 2023-02-17 143319_TABLE.png
    9.4 KB · Views: 112
Add some debugs so you can see what you are actually comparing against what you think you are comparing;
Code:
Private Sub D001_Click()

  Debug.print "UKVB:" & Me.UVKB & " Lookup:" & DLookup("ID", "Registrovani")

  If Me.UVKB.Value = DLookup("ID", "Registrovani", ???) Then
    DoCmd.Close acForm, 500
    DoCmd.OpenForm (0)
  End If
End Sub

In the immediate window (Press ctrl +G to see it) in the VBA editor you will see what you are processing.
 
How did you get such a large value for the ID?
Anyway, what is the value of UVKB? :(

Please post code so that it can be copied if need be. Pictures are fine for showing errors, but not code most times.
See my link for debugging in my signature.
 
@ Minty: Debugging looks fine. But I don't get any error information from VBA.

@ Gasma: VBA has gave me random value, that is why ID number is so large. Value from UVKB is the same (I looked in Table, to gave the same number in textbox).

In attachment you can find code and more pictures.
 

Attachments

  • Screenshot 2023-02-17 151648_B.png
    Screenshot 2023-02-17 151648_B.png
    47.6 KB · Views: 100
  • Screenshot 2023-02-17 150959_A.png
    Screenshot 2023-02-17 150959_A.png
    83.7 KB · Views: 100
  • Form_500.zip
    Form_500.zip
    436 bytes · Views: 118
Upload your DB. Compacted and zipped if to big without doing that, or at least enough to see the problem, as all looks OK from here? :(

I always used incremental. Eassier to spot any link errors in my view.

Have you tried walking through the code with F8?
 
Your form names need to be in quotes

DoCmd.Close acForm, "500"
DoCmd.OpenForm "0"

I would strongly advise against using numbers as names for any object, it can lead to some strange errors.
 
Thanks a lot of guys,

I found a problem :)

Problem was in format of UVKB in form 500 hehehe... Because in Table ID cell is defined as General Number, thats why must be also defines UVKB as general number.
I saw that, when I saw position on number in Table (from right to left) and in textbox was from left to right. Then I understood hehe...

Many thanks to bouth of you!!!
 
FWIW see here how to correctly export objects from Access as backup/import elsewhere.

 

Users who are viewing this thread

Back
Top Bottom