MedVision ad

VB6 Problem...URGENT!!! (2 Viewers)

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
also - sorry - before you do too much with the database:
I would change your field names so they have no punctuation/spaces etc in them...
If you have a field called "Price (Child)", with a space in the middle, you will always have to refer to it in your program with [ square brackets ] around the code... this gets annoying... just change it to something like price_child and simplify life....
 

dis_armer

New Member
Joined
Jul 20, 2003
Messages
14
ok, thanks for that, i'll give it a go. that module you spoke about, well it was actually useless and so i deleted it, but still get that msg saying cant find module.
 

dis_armer

New Member
Joined
Jul 20, 2003
Messages
14
righteeo,
if i put
set RS = DB.openrecordset(sqlquery)
above
sqlQuery = "SELECT * FROM flights WHERE from ='" & cityfrom.Text & "' and to = '" & cityto.Text & "'"
i gwt runtime error 3078
the microsoft jet database engine cannot find the input table or query. make sure it exists and that its name is spelt correctly.

if i put
Set RS = DB.OpenRecordset(sqlQuery)
below
sqlQuery = "SELECT * FROM flights WHERE from ='" & cityfrom.Text & "' and to = '" & cityto.Text & "'"
it runs throuh but gets no matchs, which it should because i choose criteria that matched the db.
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
if i put
Set RS = DB.OpenRecordset(sqlQuery)
below
sqlQuery = "SELECT * FROM flights WHERE from ='" & cityfrom.Text & "' and to = '" & cityto.Text & "'"
it runs throuh but gets no matchs, which it should because i choose criteria that matched the db.
VB runs through your code sequentially. Trying to execute OpenRecordset(sqlQuery) before you've told VB what sqlQuery is that line doesn't work. This is a fundamental the way VB works..something you should be familiar with.


it runs throuh but gets no matchs, which it should because i choose criteria that matched the db.
First lets look at your code:
Code:
Private Sub commnext_Click()
Unload Me
Load flights
flights.Show

Dim sqlQuery As String
' search the database with the SQL string
' looking for the person with the name entered
' in the textbox
sqlQuery = "SELECT * FROM Flights WHERE from ='" & cityfrom.Text & "' and to = '" & cityto.Text & "'"
    
Set RS = DB.OpenRecordset(sqlQuery)
    
' this on error resume next will catch errors
' if there are no matches in the database
On Error Resume Next
    
' try and show the second field of the search
' result (0 being the first, and 1 being the second)
MsgBox RS.Fields(0).Value

' if there is nothing in the recordset, it means
' the search returned nothing. So let the user know
If Err.Number = 3021 Then
    MsgBox "no match"
End If

End Sub
The first line in that sub is Unload Me. If you've unloaded this, which is where cityfromand citytoresides, VB will not know the values of cityfrom.Text and cityto.text because they've been unloaded. Because they've been unloaded, then you've referenced the comboboxes again they get reloaded into memory and they're values will be their initial values, which are "Select A City" and "Select A City" for both comboboxes.

Some things for strongly suggested reading:
Variables in VB
Control Flow
 

dis_armer

New Member
Joined
Jul 20, 2003
Messages
14
YES YES YES!!!!!!!!!
I finally understand it. It works now.......HOORAY!!!!!!!!

Thanks for all the help guys!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Top