Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question concerning "VB, Access" connection

Status
Not open for further replies.

Monzer

Programmer
May 24, 2002
26
CA
I'm trying to retreive specific recods from access to vb through a connection i made; the users select from 3 choices in comboBox ("Last Name" or "Phone#" or "Genie#")to populate the feilds. Here is my code, could somebody tell me whats wrong with it:

On Error GoTo OOPS
Dim Mystring As String
Dim mytxt As String
Screen.MousePointer = ccArrowQuestion

Mystring = "cmbfind.Text"
mytxt = "txtfind"

Data1.RecordSource = "SELECT * FROM [FOB Cutomer] WHERE Mystring = '" & mytxt & " "

Data1.Refresh

Data1.Recordset.MoveLast: Data1.Recordset.MoveFirst
MsgBox Data1.Recordset.RecordCount & " matches found."
Exit Sub
OOPS:
MsgBox "No Records Found"
End Sub
 
Is this really how you have it coded?

Mystring = "cmbfind.Text"
mytxt = "txtfind"


I would think it would be something like:

Mystring = cmbfind.Text
mytxt = txtfind.Text

That might have just been a typo or something.

jitter
 
Hi

MyString should be the field name in the table

You also need to put the second ' at the end of the SQL

Data1.RecordSource = "SELECT * FROM [FOB Cutomer] WHERE Fieldname = '" & mytxt & "'"




 
thanks for the help but it still dosen't work....!!!!
 
So what is happening? Error? No records?
Repost your select statement for the recordsource AND also post the Actual values by putting a toggle on the Datasource line, copying the datasource string into the debug window as follows(starting with a question mark):

?"SELECT * FROM [FOB Cutomer] WHERE Mystring = '" & mytxt & "'"

The hit "Enter". Now copy the actual string used and post it here as well.
 
Possibly a side note.. or possibly the root of the problem. If your field names contain the pound sign, you'll need to enclose them in brackets so as not to confuse Access. Something like:
Data1.RecordSource = "SELECT * FROM [FOB Cutomer] WHERE [" & Mystring & "] = '" & mytxt & "'"
 
Thankx for the help everybody, but i'm still getting no records when i do the search
 
Well, we probably will not be able to help you unless you answer and do the simple questions above:

So what is happening? Error? No records?
Repost your select statement for the recordsource AND also post the Actual values by putting a toggle on the Datasource line, copying the datasource string into the debug window as follows(starting with a question mark):

?"SELECT * FROM [FOB Cutomer] WHERE Mystring = '" & mytxt & "'"

The hit "Enter". Now copy the actual string used and post it here as well.


I asked for a repost so we could see what the SELECT statement looks like now after the changes requested by the people above.
I also asked for the actual values so we could review the actual SELECT string being used in order to see what the field name looks like and the criteria.

Please do this and maybe someone can help more....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top